<template>
  <transition name="dialog-fade">
  <div class="qr-dialog_wrapper" v-show="visible" @click.self="handleClose">
    <div class="qr-dialog" :style="{width, marginTop: top}">
      <div class="qr-dialog_header">
        <slot name="title">
        <span class="qr-dialog_title">{{title}}</span>
        </slot>
        <div class="qr-dialog_headerbtn" @click="handleClose">
          <i class="qr-icon-close"></i>
        </div>
      </div>
      <div class="qr-dialog_body">
       <slot></slot>
      </div>
      <div class="qr-dialog_footer" v-if="$slots.footer">
        <slot name="foot">
          <qr-button @click="handleClose">取消</qr-button>
          <qr-button type="primary" @click="handleClose">确定</qr-button>
        </slot>
      </div>
    </div>
  </div>
  </transition>
</template>

<script>
export default {
  name: 'qrDialog',
  components: {
  },
  props: {
    title: {
      type: String,
      default: '提示'
    },
    width: {
      type: String,
      default: '50%'
    },
    top: {
      type: String,
      default: '15vh'
    },
    footer: {
      type: Object
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleClose () {
      this.$emit('update:visible', false) 
    }
  }
}

</script>

<style lang="scss" scoped>
  .qr-dialog_wrapper{
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  margin: 0;
  z-index: 2001;
  background-color: rgba(0,0,0,0.5);
  .qr-dialog{
    position: relative;
    margin: 15vh auto 50px;
    background: #fff;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    box-sizing: border-box;
    width: 25%;
    &_header{
      padding: 20px 20px 10px;
      .qr-dialog_title{
        line-height: 24px;
        font-size: 18px;
        color: #303133;
      }
      .qr-dialog_headerbtn{
        position: absolute;
        top: 18px;
        right: 5px;
        padding: 0;
        background: transparent;
        border: nqr;
        outline: nqr;
        cursor: pointer;
        width: 40px;
        border: none;
        font-size: 20px;
        .qr-icon-close{
          color: #909399;
        }
      }
    }
    &_body{
      padding: 30px 35px;
      color: #606266;
      font-size: 15px;
      word-break: break-all;
    }
    &_footer{
      padding: 10px 20px 20px;
      text-align: right;
      box-sizing: border-box;
      ::v-deep .qr-button:first-child{
        margin-right: 20px;
      }
    }
  }
}
.dialog-fade-enter-active{
  animation: fade .3s;
}
.dialog-fade-leave-active{
  animation: fade .3s reverse;
}
@keyframes fade{
  0% {
    opacity: 0;
    transform: translateY(-50px);
  }
  100%{
    opacity: 1;
    transform: translateY(0);
  }
}
</style>
